/*------------------------------------------------------------------------------
 * PROJ : Prototype
 * NAME : sculove.spring.framework.util.Configuration.java
 *        
 * Copyright 2009 Administrator All rights reserved
 *------------------------------------------------------------------------------
 */
package sculove.spring.framework.util;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <pre>
 * sculove.spring.framework.util.Configuration.java
 * 
 * 시스템 환경 파일 저장 - framework.config
 * 업무 상수 파일 저장 - framework.const
 * 
 * </pre>
 * 
 * @date : 2009. 11. 28. 오후 3:53:31
 * @version :
 * @author : sculove
 */
public class Configuration {
	private static Log logger = LogFactory.getLog("Configuration");
	
	private static XMLConfiguration xmlInstance = null;
	private static PropertiesConfiguration propInstance = null;
	
	private Configuration() {}
	
	/**
	 * framework.config 프로퍼티에 지정된 XML파일의 데이터를 로드
	 * @return
	 */
	public synchronized static XMLConfiguration getXmlInstance() {
		if(xmlInstance == null) {
            try{
            	xmlInstance = new XMLConfiguration(System.getProperty("framework.config"));
                if(logger.isInfoEnabled()) logger.info("Create XML Configuration!");
            }catch(ConfigurationException ce){
                ce.printStackTrace();
            }
		}
		return xmlInstance;
	}
	
	/**
	 * framework.const 프로퍼티에 지정된 Properties 파일의 데이터를 로드
	 * @return
	 */
	public synchronized static PropertiesConfiguration getPropInstance() {
		if(propInstance == null) {
            try{
            	propInstance = new PropertiesConfiguration(System.getProperty("framework.const"));
                if(logger.isInfoEnabled()) logger.info("Create Properties Configuration!");
            }catch(ConfigurationException ce){
                ce.printStackTrace();
            }
		}
		return propInstance;
	}	
	
	/**
	 * XML Configuration 파일 refresh
	 */
	public synchronized static void refreshXml() {
		Configuration.getXmlInstance().reload();
		if(logger.isInfoEnabled()) logger.info("Refresh XML Configuration...");
	}
	
	/**
	 * Properties 파일 refresh 
	 */
	public synchronized static void refreshProp() {
		Configuration.getPropInstance().reload();
		if(logger.isInfoEnabled()) logger.info("Refresh Properties Configuration...");
	}
}
